import { ObjCreate } from "../common/ObjCreate";
import { ImagesConst } from "../../resource/ImagesConst";
import { BaseItem } from "../common/BaseItem";
import { DragEvent } from "../../../../com/mui/events/DragEvent";
import { GTextFormat } from "../../../common/GTextFormat";
import { ItemData } from "../../resource/info/ItemData";
import { SearchConditionData } from "./SearchConditionData";
import { EMarketOrder } from "../../../../Message/Game/EMarketOrder";
import { EMarketRecordType } from "../../../../Message/Game/EMarketRecordType";
import { Cache } from "../../cache/Cache";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SMarketItem } from "../../../../Message/Game/SMarketItem";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { GNumericStepper } from "../../../../com/mui/controls/GNumericStepper";
type int = number;
//class QuickSellGoodsItem
    
    export  class QuickSellGoodsItem /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.init();
            return;
        }

        public get isSearch(): Boolean
        {
            return this._isSearch;
        }

        public set isSearch(arg1: Boolean)
        {
            this._isSearch = arg1;
            return;
        }

        public get numSell(): int
        {
            return this._numStepper.value;
        }

        public get unitPrice(): int
        {
            return this._unitPrice;
        }

        public get unit(): int
        {
            if (this._sMarketItem) 
            {
                return this._sMarketItem.sellUnit;
            }
            return -1;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBitmap(ImagesConst.PackItemBg, 5, 0, this);
            this._baseItem = new BaseItem();
            this._baseItem.x = 8;
            this._baseItem.y = 3;
            this._baseItem.setSize(33, 33);
            addChild(this._baseItem);
            this._baseItem.addEventListener(DragEvent.Event_Move_In, this.onItemMoveInHandler);
            this._baseItem.addEventListener(DragEvent.Event_Throw_goods, this.onItemThrowGoodsHandler);
            this._baseItem.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClickHandler);
            var loc1=new GTextFormat("", 12, 268419072);
            this._priceTxt = ObjCreate.createTextField("", 20, 50, 50, 20, this, loc1);
            this._resNumTxt = ObjCreate.createTextField("", 0, 85, 50, 20, this, loc1);
            this._numStepper = ObjCreate.createGNumericStepper(0, 120, 50, 22, this);
            this._numStepper.addEventListener(flash.events.Event.CHANGE, this.onNumStepperChangeHandler);
            this._coinBg = ObjCreate.createBitmap(ImagesConst.Tongqian_small, 0, 52, this);
            this._coinBg.visible = false;
            this._goldBg = ObjCreate.createBitmap(ImagesConst.Yuanbao_small, 0, 52, this);
            this._goldBg.visible = false;
            return;
        }

        /* internal  */onItemMoveInHandler(arg1: DragEvent): void
        {
            var loc1=arg1.dragItem as BaseItem;
            var loc2=loc1.itemData;
            this.setItemData(loc2);
            return;
        }

        public setItemData(arg1: ItemData): void
        {
            this._isSearch = true;
            var loc1=arg1.itemInfo.item.code;
            this._baseItem.itemData = arg1;
            this._numStepper.maximum = arg1.itemAmount;
            var loc2=new Map<any, any> /* flash.utils.Dictionary */();
            loc2[loc1] = loc1;
            SearchConditionData.codesMap = loc2;
            SearchConditionData.career = 0;
            SearchConditionData.color = 0;
            SearchConditionData.levelLower = 1;
            SearchConditionData.levelUpper = 100;
            SearchConditionData.order = EMarketOrder._EMarketOrderDesc;
            SearchConditionData.recordType = EMarketRecordType._EMarketRecordTypeSeekBuy;
            SearchConditionData.targetPage = 1;
            Cache.instance.market.quickSearchType = 0;
            Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSearch, null, true));
            return;
        }

        /* internal  */onItemThrowGoodsHandler(arg1: DragEvent): void
        {
            this.reset();
            return;
        }

        /* internal  */onItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.reset();
            return;
        }

        public updateData(arg1: SMarketItem): void
        {
            this._sMarketItem = arg1;
            if (arg1) 
            {
                this._unitPrice = arg1.sellPrice;
                this._priceTxt.text = this._unitPrice + "";
                this._resNumTxt.text = arg1.amount + "";
                this._numStepper.value = 1;
                if (this._sMarketItem.amount < this._numStepper.maximum) 
                {
                    this._numStepper.maximum = this._sMarketItem.amount;
                }
                if (arg1.sellUnit != EPrictUnit._EPriceUnitCoin) 
                {
                    if (arg1.sellUnit == EPrictUnit._EPriceUnitGold) 
                    {
                        this._coinBg.visible = false;
                        this._goldBg.visible = true;
                    }
                }
                else 
                {
                    this._coinBg.visible = true;
                    this._goldBg.visible = false;
                }
            }
            else 
            {
                this._priceTxt.text = "0";
                this._resNumTxt.text = "0";
                this._coinBg.visible = false;
                this._goldBg.visible = false;
            }
            return;
        }

        public reset(): void
        {
            this._baseItem.itemData = null;
            this._coinBg.visible = false;
            this._goldBg.visible = false;
            this._priceTxt.text = "";
            this._resNumTxt.text = "";
            this._numStepper.value = 1;
            this._isSearch = false;
            this._unitPrice = 0;
            dispatchEvent(new DataEvent(EventName.MarketNumStepperChange));
            return;
        }

        public sellGoods(): void
        {
            if (this._sMarketItem && this._baseItem.itemData && this._numStepper) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.MarketSellGoods, {"marketId": this._sMarketItem.marketId, "uid": this._baseItem.itemData.uid, "amount": this._numStepper.value}));
            }
            return;
        }

        /* internal  */onNumStepperChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            dispatchEvent(new DataEvent(EventName.MarketNumStepperChange));
            return;
        }

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_priceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_resNumTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_numStepper: GNumericStepper;

        /* internal */ /* var */_isSearch: Boolean=false;

        /* internal */ /* var */_unitPrice: int;

        /* internal */ /* var */_coinBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_goldBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sMarketItem: SMarketItem;
    }
